package com.wind.lambda;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static java.util.concurrent.Executors.*;

/**
 * Lambda表达式 创建线程对象
 *
 * @author Wind
 */
public class LambdaTest05 {
    public static void main(String[] args) {
        /*
            Runable
         */
        // 以前写法
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("OK~!");
            }
        }).start();

        // Lambda表达式创建
        new Thread(() -> {
            System.out.println("OK~!");
        }).start();

        // 简化上面Lambda
        new Thread(() -> System.out.println("OK~!")).start();

        /*
            提交
         */
        ExecutorService executorService = newCachedThreadPool();
        // Runable（无返回值）
        executorService.submit(() -> {
            System.out.println("OK~!");
        });
        // Callable（有返回值）
        executorService.submit(() -> {
            return "完成了！";
        });

    }
}